﻿Type=Activity
Version=3.15
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Dim V_XM As String
	Dim V_CH As String
	Dim V_JYRQ As Int
	Dim V_YBH As Int
	Dim V_YQBM As String

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Dim scvJG As ScrollView
	Dim pnlJG As Panel
	Dim pnlTop As Panel
	
	Dim HttpJobTool As HttpJob
	
	Dim FontSizeSM,FontSizeNR As Float
	Dim FontColorSM,FontColorNR As Int
	
	Dim lsBHRecords,lsJGRecords As List
	
	FontSizeSM = 16
	FontSizeNR = 16
	
	FontColorSM = Colors.White
	FontColorNR = Colors.Red
	
	
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormBHJYJGInfo")
	Activity.Title = "病人检验结果信息-"  & V_CH & " " &V_XM 
	
	pnlJG = scvJG.Panel
	
	InitLayOut
	
End Sub

Sub Activity_Resume
	RefreshData
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub InitLayOut
	Dim iLeft1,iLeft2,iLeft3,iLeft4,iTop1,iWidth,iHeight As Int
	Dim iLeft11,iLeft12,iLeft13,iLeft14 As Int
	
	RemoveAll
	
	iHeight = PublicVar.GV_ListView_ItemHeight
	iLeft1 = 0
	iLeft2 = 25%X
	iLeft3 = 50%X
	iLeft4 = 75%X
	
	iTop1 = 5
	iWidth = PublicVar.GV_ListView_ItemHeight * 2 
	
	AddSMLabel("姓名","XM",iLeft1,iTop1,iWidth -20,iHeight)
	AddSMLabel("性别","XB",iLeft2,iTop1,iWidth,iHeight)	
	AddSMLabel("年龄","NL",iLeft3,iTop1,iWidth -20,iHeight)	
	AddSMLabel("样本号","YBH",iLeft4,iTop1,iWidth+20,iHeight)
	
	AddSMLabel("科室","KSMC",iLeft1,iTop1 + iHeight ,iWidth -20,iHeight)
	AddSMLabel("住院号","ZYH",iLeft2,iTop1 + iHeight,iWidth,iHeight)
	AddSMLabel("床号","CH",iLeft3,iTop1 + iHeight,iWidth -20,iHeight)
	AddSMLabel("样本类别","YBMC",iLeft4,iTop1 + iHeight,iWidth+20,iHeight)
	
	AddJYBTLabel("检验项目","JYXM_T",0,iTop1 + iHeight * 2,35%X,iHeight)
	AddJYBTLabel("提示","TS_T",35%X,iTop1 + iHeight * 2,10%X,iHeight)
	AddJYBTLabel("检验值","JYZ_T",45%X,iTop1 + iHeight * 2,20%X,iHeight)
	AddJYBTLabel("单位","DW_T",65%X,iTop1 + iHeight * 2,10%X,iHeight)
	AddJYBTLabel("参考值","CKZ_T",75%X,iTop1 + iHeight * 2,25%X,iHeight)
	
	
	'内容
	iHeight = PublicVar.GV_ListView_ItemHeight
	iWidth = PublicVar.GV_ListView_ItemHeight * 2
	
	iLeft11 = 0%X + iWidth -15 
	iLeft12 = 25%X + iWidth + 5
	iLeft13 = 50%X + iWidth -15 
	iLeft14 = 75%X + iWidth+25
	
	iTop1 = 5
	
	
	AddNRLabel("姓名","XM",iLeft11,iTop1,iLeft2 - iLeft11 + 20,iHeight)
	AddNRLabel("性别","XB",iLeft12,iTop1,iLeft3 - iLeft12,iHeight)	
	AddNRLabel("年龄","NL",iLeft13,iTop1,iLeft4 - iLeft13,iHeight)	
	AddNRLabel("样本号","YBH",iLeft14,iTop1,100%X - iLeft14,iHeight)
	
	AddNRLabel("科室","KSMC",iLeft11,iTop1 + iHeight ,iLeft2 - iLeft11 + 20,iHeight)
	AddNRLabel("住院号","ZYH",iLeft12,iTop1 + iHeight,iLeft3 - iLeft12,iHeight)
	AddNRLabel("床号","CH",iLeft13,iTop1 + iHeight,iLeft4 - iLeft13,iHeight)
	AddNRLabel("样本类别","YBMC",iLeft14,iTop1 + iHeight,100%X - iLeft14,iHeight)	
	
	
	pnlTop.Height = iTop1 + iHeight * 3 +2
	pnlJG.Height = 0
	
	scvJG.Top = pnlTop.Height
	scvJG.Left = 0
	scvJG.Width = 100%X
	scvJG.Height = 100%y - scvJG.Top
End Sub

Sub AddSMLabel(AText As String,AField As String,ALeft As Int,ATop As Int,AWidth As Int,AHeight As Int)
	Dim lblSM As Label

	lblSM.Initialize("lblSM")
	lblSM.Text = AText
	lblSM.Gravity = Gravity.RIGHT
	lblSM.TextSize = FontSizeSM
	'lblSM.Color = FontColorSM
	lblSM.TextColor = FontColorSM
	lblSM.Tag = 0
	
	pnlTop.AddView(lblSM,ALeft,ATop,AWidth,AHeight)
End Sub

Sub AddNRLabel(AText As String,AField As String,ALeft As Int,ATop As Int,AWidth As Int,AHeight As Int)
	Dim lblNR As Label

	lblNR.Initialize("lblNR")
	lblNR.Text = AText
	lblNR.Gravity = Gravity.LEFT
	lblNR.TextSize = FontSizeNR
	'lblNR.Color = 
	lblNR.TextColor = FontColorNR
	lblNR.Tag = AField
	
	pnlTop.AddView(lblNR,ALeft,ATop,AWidth,AHeight)
End Sub

Sub AddJYBTLabel(AText As String,AField As String,ALeft As Int,ATop As Int,AWidth As Int,AHeight As Int)
	Dim lblSM As Label

	lblSM.Initialize("lblJYBT")
	lblSM.Text = AText
	lblSM.Gravity = Gravity.CENTER
	lblSM.TextSize = FontSizeSM
	'lblSM.Color = FontColorSM
	lblSM.TextColor = FontColorSM
	lblSM.Tag = 1
	
	pnlTop.AddView(lblSM,ALeft,ATop,AWidth,AHeight)

End Sub

Sub RemoveAll
  For i = pnlJG.NumberOfViews -1 To 0 Step -1
      pnlJG.RemoveViewAt(i)
  Next
  pnlJG.Height = 0
	
	For i = pnlTop.NumberOfViews -1 To 0 Step -1
		pnlTop.RemoveViewAt(i)	
	Next
End Sub

Sub ClearAllNR
	ClearBHNR
	ClearJGNR
End Sub

Sub ClearJGNR
  For i = pnlJG.NumberOfViews -1 To 0 Step -1
      pnlJG.RemoveViewAt(i)
  Next
  pnlJG.Height = 0
	
End Sub

Sub ClearBHNR
	Dim lblNR As Label
  For i = pnlTop.NumberOfViews -1 To 0 Step -1
    lblNR = pnlTop.GetView(i)
		
		If lblNR.Tag<>0 AND lblNR.Tag<>1 Then
			lblNR.Text = ""	
		
		End If
		
  Next
End Sub


Sub RefreshData
	Dim sURL,sSession,sText,sJYRQ,sYBH,sYQBM As String
	
	ClearAllNR
	
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	
	sJYRQ = PublicVar.GV_DesTool.Base64encrypt(V_JYRQ)
	sYBH = PublicVar.GV_DesTool.Base64encrypt(V_YBH)
	sYQBM = PublicVar.GV_DesTool.Base64encrypt(V_YQBM)
	
	sText = "Session=" & sSession & "&JYRQ=" & sJYRQ & "&YBH=" & sYBH & "&YQBM=" & sYQBM

	sURL = PublicVar.GetServerUrl&"/getbhjyjginfo"
	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)
	ProgressDialogShow("正在获取数据，请稍候...")	


End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				HttpJobSuccess(Job)
      End If
   Else
		HttpJobError(Job)
   End If
   Job.Release
End Sub

Sub HttpJobSuccess(Job As HttpJob)  
	Dim sResult,sCode,sData,sBHData,sJGData As String
	Dim mapResult As Map
	
	ProgressDialogHide
	
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		ToastMessageShow("获取数据失败"&CRLF &sResult, True)
		
		PublicVar.CheckSession(sCode)
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
		ToastMessageShow("获取数据失败"&CRLF &"返回的数据为空", True)	
		Return	
	
	End If
	
	sData = PublicVar.GV_DesTool.Base64decrypt(sData)
	PublicVar.GV_JSonTool.Initialize(sData)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sBHData = mapResult.Get("BHData")
	sBHData = PublicVar.GV_DesTool.Base64decrypt(sBHData)
	PublicVar.GV_JSonTool.Initialize(sBHData)
	lsBHRecords = PublicVar.GV_JSonTool.NextArray
	SetBHInfo(lsBHRecords)
	
	sJGData = mapResult.Get("JGData")
	sJGData = PublicVar.GV_DesTool.Base64decrypt(sJGData)
	PublicVar.GV_JSonTool.Initialize(sJGData)
	lsJGRecords = PublicVar.GV_JSonTool.NextArray
	SetJGInfo(lsJGRecords)	

End Sub

Sub HttpJobError(Job As HttpJob) 
	Dim sMsg As String
	ProgressDialogHide
	
	Log("Error: " & Job.ErrorMessage)
	sMsg = "获取病人检验结果信息失败."& CRLF & Job.ErrorMessage 
  ToastMessageShow(sMsg, True)
End Sub

Sub SetBHInfo(lsRecords As List)
	Dim sText,sField As String
	Dim mapResult As Map
	
	For i = 0 To lsRecords.Size - 1 
		mapResult = lsRecords.Get(i)
		
		For j = 0 To mapResult.Size -1 
			sField = mapResult.GetKeyAt(j)
			sText = mapResult.GetValueAt(j)
			SetBHLabelNR(sText,sField)
		
		Next
	Next
End Sub

Sub SetJGInfo(lsRecords As List)
	Dim iTop1,iWidth,iHeight,iColor As Int
	Dim sXMMC,sJYXM,sTS,sJYZ,sDW,sMinCKZ,sMaxCKZ,sCKZ As String
	Dim fMinCKZ,fMaxCKZ,fJYZ As Float
	Dim mapResult As Map
	
	iHeight = PublicVar.GV_ListView_ItemHeight
	iTop1 = 5
	
	ClearJGNR
	
	For i = 0 To lsRecords.Size - 1 
		mapResult = lsRecords.Get(i)
		
		sXMMC = mapResult.Get("XMMC")
		sJYXM = mapResult.Get("JYXM")
		sDW = mapResult.Get("DW")
		sJYZ = mapResult.Get("JYZ")
		sMinCKZ = mapResult.Get("MINCKZ")
		sMaxCKZ = mapResult.Get("MAXCKZ")
		
		If sJYXM<>"" Then
			sXMMC = sXMMC & "(" &sJYXM& ")"	
		End If
		
		iColor = Colors.White
		sTS = ""
		sCKZ = ""
		If IsNumber(sJYZ) AND IsNumber(sMinCKZ) AND IsNumber(sMaxCKZ) Then
			fMinCKZ = mapResult.Get("MINCKZ")
			fMaxCKZ = mapResult.Get("MAXCKZ")
			fJYZ = mapResult.Get("JYZ")		
			
			If fJYZ<fMinCKZ Then
				sTS = "↓ "
				iColor = Colors.Blue
			Else If fJYZ>fMaxCKZ Then
				sTS = "↑"
				iColor = Colors.Red
			End If
			
			sCKZ = mapResult.Get("MINCKZ") & "～" & mapResult.Get("MAXCKZ")  '参考范围 ↓ ↑
		End If
		
		AddJYJGNR(sXMMC,"JYXM",5,iTop1 + iHeight * i ,40%X,iHeight,iColor,Gravity.LEFT)
		AddJYJGNR(sTS,"TS",40%X,iTop1 + iHeight * i,5%X,iHeight,iColor,Gravity.LEFT)
		AddJYJGNR(sJYZ,"JYZ",45%X,iTop1 + iHeight * i,20%X,iHeight,iColor,Gravity.CENTER)
		AddJYJGNR(sDW,"DW",65%X,iTop1 + iHeight * i,10%X,iHeight,iColor,Gravity.CENTER)
		AddJYJGNR(sCKZ,"CKZ",75%X,iTop1 + iHeight * i,25%X,iHeight,iColor,Gravity.CENTER)		
		
	Next
	
	pnlJG.Height = iTop1 + iHeight * lsRecords.Size
	
End Sub

Sub SetBHLabelNR(AText As String,AField As String)
	Dim lblNR As Label
  For i = pnlTop.NumberOfViews -1 To 0 Step -1
    lblNR = pnlTop.GetView(i)
		
		If lblNR.Tag=AField  Then
			lblNR.Text = AText	
		
		End If
		
  Next

End Sub

Sub AddJYJGNR(AText As String,AField As String,ALeft As Int,ATop As Int,AWidth As Int,AHeight As Int,AColor As Int,AGravity As Int)
	Dim lblSM As Label

	lblSM.Initialize("lblJGNR")
	lblSM.Text = AText
	lblSM.Gravity = AGravity
	lblSM.TextSize = FontSizeSM
	'lblSM.Color = FontColorSM
	lblSM.TextColor = AColor
	lblSM.Tag = 1
	
	pnlJG.AddView(lblSM,ALeft,ATop,AWidth,AHeight)

End Sub
